package com.guodi.map.feign;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guodi.map.entity.MapDivision;
import com.guodi.map.entity.MapProjectDir;
import com.guodi.map.service.IMapDivisionService;
import com.guodi.map.service.IMapProjectDirService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @描述: Map服务Feign实现类
* @作者: 代鹏刚
* @日期: 2021/1/20 10:49
**/


@ApiIgnore
@RestController
@AllArgsConstructor
@Slf4j
public class MapClient implements IMapClient {

	private final IMapDivisionService iMapDivisionService;

	private final IMapProjectDirService mapProjectDirService;


	/**
	 * @描述: 查询全部行政区划
	 * @入参:
	 * @出参:
	 * @作者: 陈宏成
	 * @日期: 2022-01-20
	 */
	@Override
	public Map<String, String> mapAllDivision(){
		LambdaQueryWrapper<MapDivision> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.select(MapDivision::getCode, MapDivision::getName);
		List<MapDivision> list = this.iMapDivisionService.list(queryWrapper);
		Map<String, String> collect = list.stream().collect(Collectors.toMap(MapDivision::getCode, MapDivision::getName));
		return collect;
	}

	@Override
	public MapDivision mateByCode(String divisionCode) {
		return iMapDivisionService.mateByCode(divisionCode);
	}

	@Override
	public List<MapDivision> findByCode(String divisionCode) {
		return iMapDivisionService.findByCode(divisionCode);
	}

	@Override
	public List<MapProjectDir> listTreeByCodeAndParentId(String projectCode, String parentId, Boolean isDir) {
		return mapProjectDirService.listTreeByCodeAndParentId(projectCode,parentId,isDir);
	}

	@Override
	public List<MapProjectDir> createTree(String parentId, List<MapProjectDir> mapProjectDirs) {
		return mapProjectDirService.createTree(parentId,mapProjectDirs);
	}

    @Override
    public Map<String, String> mapDivisionCode2Name(String[] divisionCodes) {
	    log.info("divisionCodes = {}", divisionCodes);
        Map<String, String> map = iMapDivisionService.mapDivisionCode2Name(Arrays.asList(divisionCodes));
        return map;
    }

    @Override
    public String getNameByCode(String code) {
	    log.info("code = {}", code);
        String name = iMapDivisionService.getNameByCode(code);
        return name;
    }

    @Override
    public List<MapDivision> listDataByCode(String code) {
        List<MapDivision> mapDivisions = iMapDivisionService.listDataByCode(code);
        return mapDivisions;
    }
}
